function SwitchDemo() {
    this.sectorTitles = {
	"telco" : "telecommunications",
	"utilities" : "utilities",
	"resource" : "natural resources",
	"government" : "state and local government",
	"financial" : "banking and financial services"
    };

    this.sectorDemoTitles = {
	"telco" : ["Retail Performance Analysis", "Incident Resolution", "Tower Coverage"],
	"utilities" : ["Incident Resolution", "Utilities Management"],
	"resource" : ["Pipeline Routing", "Offshore Prospecting"],
	"government" : ["Project Management", "Emergency Planning"],
	"financial" : ["Branch Performance", "financial2"]
    };

    this.isOpen = false;

    this.jDiv = null;
    this.jIndustryName = null;
    this.jDemoButtons = null;
    this.jIndustryButtons = null;

    this.init = function() {
	this.jDiv = $('<div style="overflow:hidden;"><center><table style="width:100%;"><tbody><tr><td style="background:white;width:345px;"><span class="redText">Talk</span> to us<iframe id="switch_form_frame" style="width:345px;height:535px;overflow-x:hidden;overflow-y:auto;border:none;" src="http://lp.google-mkto.com/APACGEODiscoverWeb_Form2.html"></iframe></td><td style="background:white;"><center><div style="vertical-align:middle;margin-top:64px;"><center>Select another demo<br/><br/><div id="switch_demo_buttons" style="vertical-align:top;">(buttons)</div><br/>Browse another industry<br/><br/><div id="switch_industry_buttons">(buttons)</div></center></div></center></td></tbody></table></center></div>');
	$('body').append(this.jDiv);
	this.jDiv.dialog({dialogClass:'noTitle', width:937, height:591, resizable:false, zIndex:10000, position:['center', 'center'], closeOnEscape:false, autoOpen:false});
		
		_gaq.push(['_trackEvent', '(' + currentSector + currentSectorNumber + ') Demo contact form overlay', 'Form Load', 'Submit contact form']);
    };

    this.show = function() {
	switchDemoUI.jDiv.dialog('open');
	$('#switch_form_frame').show();
	this.isOpen = true;
    };

    this.hide = function() {
	switchDemoUI.jDiv.dialog('close');
	$('#switch_form_frame').hide();
	this.isOpen = false;
    };

    this.setDemo = function (sector, number) {
	var html = null;
	this.jIndustryName = $('#switch_industry_name');
	this.jDemoButtons = $('#switch_demo_buttons');
	this.jIndustryButtons = $('#switch_industry_buttons');

	// Industry title
	this.jIndustryName.html(this.sectorTitles[sector]);

	// Demo buttons
	html = "";
	if (sector == "telco") {
	    if (number == -1) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, 2, false);
	    } else if (number == 1) {
		html += this.createDemoButton(sector, 2, false);
		html += this.createDemoButton(sector, number, true);
	    } else if (number == 2) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, number, true);
	    } else if (number == 3) {
		//html += this.createDemoButton(sector, 1, false);
		//html += this.createDemoButton(sector, number, true);
	    }
	} else if (sector == "utilities") {
	    if (number == -1) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, 2, false);
	    } else if (number == 1) {
		html += this.createDemoButton(sector, 2, false);
		html += this.createDemoButton(sector, number, true);
	    } else if (number == 2) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, number, true);
	    }
	    if (number == 1) {
	    } else if (number == 2) {
	    }
	} else if (sector == "resource") {
	    if (number == -1) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, 2, false);
	    } else if (number == 1) {
		html += this.createDemoButton(sector, 2, false);
		html += this.createDemoButton(sector, number, true);
	    } else if (number == 2) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, number, true);
	    }
	    if (number == 1) {
	    } else if (number == 2) {
	    }
	} else if (sector == "government") {
	    if (number == -1) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, 2, false);
	    } else if (number == 1) {
		html += this.createDemoButton(sector, 2, false);
		html += this.createDemoButton(sector, number, true);
	    } else if (number == 2) {
		html += this.createDemoButton(sector, 1, false);
		html += this.createDemoButton(sector, number, true);
	    }
	} else if (sector == "financial") {
	    if (number == -1) {
		html += this.createDemoButton(sector, 1, false);
		//html += this.createDemoButton(sector, 2, false);
	    } else if (number == 1) {
		//html += this.createDemoButton(sector, 2, false);
		html += this.createDemoButton(sector, number, true);
	    } else if (number == 2) {
		html += this.createDemoButton(sector, 1, false);
		//html += this.createDemoButton(sector, number, true);
	    }
	}
	this.jDemoButtons.html(html);

	// Industry buttons
	html = "";
	for (var key in this.sectorTitles) {
	    if (key == sector) continue;
	    html += this.createIndustryButton(key);
	}
	this.jIndustryButtons.html(html);

    };
	
    this.createDemoButton = function(sector, number, isRepeat) {
	if (isRepeat) {
	    return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="img/demo_repeat.png"/><br/>'+this.sectorDemoTitles[sector][number-1]+'</div>';
	} else if (number == 1) {
	    return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="img/demo_one.png"/><br/>'+this.sectorDemoTitles[sector][number-1]+'</div>';
	} else if (number == 2) {
	    return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="img/demo_two.png"/><br/>'+this.sectorDemoTitles[sector][number-1]+'</div>';
	} else if (number == 3) {
	    return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="img/demo_three.png"/><br/>'+this.sectorDemoTitles[sector][number-1]+'</div>';
	}
    }

    this.createIndustryButton = function(sector) {
	return '<img style="cursor:pointer;margin:7px;" src="img/small_tiles/' + sector + '.png" onclick="loadSubDemo(\'' + sector + '\',' + 1 + ');return true;"/>';
    }

}
